package com.myh.gulimall.search.thread;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: // 类说明，在创建类时要填写
 * @ClassName: CompletableFutureTest    // 类名，会自动填充
 * @Author: MYH          // 创建者
 * @Date: 2024/5/26 9:41   // 时间
 * @Version: 1.0     // 版本
 */
public class CompletableFutureTest {

    public static ExecutorService executorService = Executors.newFixedThreadPool(100);
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future01 = CompletableFuture.supplyAsync(() -> {
            return 0;
        }, executorService);
        CompletableFuture<Integer> future02 = CompletableFuture.supplyAsync(() -> {
            return 1;
        }, executorService);
        CompletableFuture<Integer> future03 = CompletableFuture.supplyAsync(() -> {
            return 2;
        }, executorService);
        CompletableFuture.anyOf(future01, future02, future03).get();
    }
}
